<template>
	<view class="wanl-success">
		<!-- 导航条 -->
		<view class="cu-custom" :style="{ height: $wanlshop.wanlsys().height + 'px' }">
			<view
				class="cu-bar bg-bgcolor fixed"
				:style="{
					height: $wanlshop.wanlsys().height + 'px',
					paddingTop: $wanlshop.wanlsys().top + 'px'
				}"
			>
				<view class="action" @tap="onBackUser"><text class="wlIcon-fanhui1"></text></view>
				<view class="content" :style="{ top: $wanlshop.wanlsys().top + 'px' }">
					<text>{{ title }}完成</text>
				</view>
			</view>
		</view>

		<view class="content">
			<text class="icon wlIcon-pintuantuangouchenggong"></text>
			<text class="text-lg margin-tb">{{ title }}已成功</text>
			<text class="text-lg margin-tb">即将跳转到小程序....</text>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			type: '',
			title: '',
			order_no: ''
		};
	},
	onShow() {
	    // 在页面展示时设置一个定时器，1秒后执行跳转
	    // setTimeout(() => {
			// this.toWx();
	    // }, 1000);
	},
	onLoad(options) {
    uni.removeStorageSync('oid')
		if (options.type == 'pay') {
			this.title = '支付';
		} else if (options.type == 'comment') {
			this.title = '评论';
		} else if (options.type == 'feedback') {
			this.title = '反馈';
		} else if (options.type == 'withdraw') {
			this.title = '请等待后台审核，提交';
		} else if (options.type == 'recharge') {
			this.title = '充值';
		} else if (options.type == 'complaint') {
			this.title = '举报';
		} else if (options.type == 'find') {
			this.title = '作品上传';
		}
		this.type = options.type;
    if (options.order_no){
      this.order_no = options.order_no
    }else{
		let order_no = uni.getStorageSync("order_no");
		this.order_no = order_no;
	}
    console.log(options)
    // if (options.isUrl){
    this.transformation()
    // }
	},
	methods: {
		async toWx(){
			console.log(this.$store.state.statistics.order.address_id,'address_id');
			await uni.request({
							  	url: '/wanlshop/web/getDomain',
							  	method: 'POST',
							  	data: {
									'address_id':this.$store.state.statistics.order.address_id,
									'order_no':this.$store.state.statistics.order.order_no,
									'path':'/pages/user/order/order'
							  	},
							  	success: res => {
									var url = res.data.url_link
									console.log(url,'跳转链接');
									window.location.href  = url
								},
								fail: (e) => {
									
								},
							})
		},
    getUrl(){
       uni.request({
        url: '/adtf/index',
        method: 'POST',
        data: {
          'order_no':this.order_no,
          'path':'/pages/user/order/order'
        },
        success: res => {
          var url = res.data.url
          console.log(url,'跳转链接');
          window.location.href  = url
        },
        fail: (e) => {

        },
      })
    },
    transformation(){
      var self = this
      var clickID = ''
      if (uni.getStorageSync('clickid')){
        // 巨量
        clickID = uni.getStorageSync('clickid')
      }
      if (uni.getStorageSync('bxmid')){
        // 变现猫
        clickID = uni.getStorageSync('bxmid')
      }
      if (uni.getStorageSync('qz_gdt')){
        // 腾讯
        clickID = uni.getStorageSync('qz_gdt')
      }
      if (uni.getStorageSync('cili')){
        // 磁力
        clickID = uni.getStorageSync('cili')
      }
      uni.request({
        url: '/wanlshop/common/zhuanhua',
        method: 'POST',
        data:{
          clickid:clickID,
          event_type:uni.getStorageSync('event_type'),
          type:true
        },
        success: res => {
          console.log("++++++++++++++++++++++++++++++++")
          console.log(res.data)
          if (res.data){
            // 商品支付成功后调用
            if (uni.getStorageSync('clickid')){
              this.sendtoTaq();
            }
            if (uni.getStorageSync('bxmid')){
              this.sendtoTaqbxm();
            }
            if (uni.getStorageSync('qz_gdt')){
              this.sendtoQzGdt()
            }
            if (uni.getStorageSync('cili')){
              this.sendtoCiLi()
            }
          }else{
            uni.removeStorageSync('bxmid')
            uni.removeStorageSync('clickid')
            uni.removeStorageSync('qz_gdt')
            uni.removeStorageSync('cili')
            uni.removeStorageSync('host')
            uni.removeStorageSync('event_type')
          }

          self.getUrl()
        }
      });
    },
		onIndex() {
			uni.setTabBarStyle({
				backgroundColor: '#ffffff',
				borderStyle: 'white'
			});
			uni.switchTab({
				url: '/pages/index'
			});
		},
		onBackUser() {
			uni.setTabBarStyle({
				backgroundColor: '#ffffff',
				borderStyle: 'white'
			});
			uni.switchTab({
				url: '/pages/user'
			});
		},
    sendtoTaq:function (clickid) {
      console.log(clickid);
      var self = this;
      uni.request({
        method:'POST',
        url: '/index/req',
        header: {},
        data: {
          "event_type": uni.getStorageSync('event_type'),
          "clickid": uni.getStorageSync('clickid'),
        },
        success: function(res) {
          console.log('++++++++++ success   ++++++++++++++++')
          console.log(JSON.stringify(res.data))
          uni.removeStorageSync('clickid')
          uni.removeStorageSync('event_type')
        },
        error: function(err) {
          console.log('++++++++++ error   ++++++++++++++++')
          console.log(JSON.stringify(err))
        },
        finally: function(res) {
          console.log('++++++++++ finally   ++++++++++++++++')
        }
      })
      // uni.request({
      //   method:'POST',
      //   url: 'https://analytics.oceanengine.com/api/v2/conversion',
      //   header: {},
      //   data: {
      //     "event_type": uni.getStorageSync('event_type'),
      //     "context": {
      //       "ad": {
      //         "callback": uni.getStorageSync('clickid'),//callback 这里需要填写的就是从启动参数里获取的 clickid
      //       }
      //     },
      //     "timestamp": new Date().getTime()
      //   },
      //   success: function(res) {
      //     console.log('++++++++++ success   ++++++++++++++++')
      //     console.log(JSON.stringify(res.data))
      //     uni.removeStorageSync('clickid')
      //     uni.removeStorageSync('event_type')
      //   },
      //   error: function(err) {
      //     console.log('++++++++++ error   ++++++++++++++++')
      //     console.log(JSON.stringify(err))
      //   },
      //   finally: function(res) {
      //     console.log('++++++++++ finally   ++++++++++++++++')
      //   }
      // })
    },
    sendtoQzGdt:function () {
      var self = this;
      uni.request({
        method:'GET',
        url: 'https://tracking.e.qq.com/conv/web',
        header: {},
        data: {
          "clickid": uni.getStorageSync('qz_gdt'),
          "action_time": Math.floor(new Date().getTime() / 1000),
          "action_type": uni.getStorageSync('event_type'),
          "link": encodeURI(uni.getStorageSync('host')),
        },
        success: function(res) {
          console.log('++++++++++ success   ++++++++++++++++')
          console.log(JSON.stringify(res.data))
          uni.removeStorageSync('qz_gdt')
          uni.removeStorageSync('host')
          uni.removeStorageSync('event_type')
        },
        error: function(err) {
          console.log('++++++++++ error   ++++++++++++++++')
          console.log(JSON.stringify(err))
        },
        finally: function(res) {
          console.log('++++++++++ finally   ++++++++++++++++')
        }
      })
    },
    sendtoCiLi:function () {
      var self = this;
      uni.request({
        method:'GET',
        url: '/index/cilireq',
        header: {},
        data: {
          "callback": uni.getStorageSync('cili'),
          "event_time": new Date().getTime(),
          "event_type": uni.getStorageSync('event_type'),
          "purchase_amount": uni.getStorageSync('purchase_amount'),
        },
        success: function(res) {
          console.log('++++++++++ success   ++++++++++++++++')
          console.log(JSON.stringify(res.data))
          uni.removeStorageSync('cili')
          uni.removeStorageSync('event_type')
          uni.removeStorageSync('purchase_amount')
        },
        error: function(err) {
          console.log('++++++++++ error   ++++++++++++++++')
          console.log(JSON.stringify(err))
        },
        finally: function(res) {
          console.log('++++++++++ finally   ++++++++++++++++')
        }
      })
      // uni.request({
      //   method:'GET',
      //   url: 'https://ad.partner.gifshow.com/track/activate',
      //   header: {},
      //   data: {
      //     "callback": uni.getStorageSync('cili'),
      //     "event_time": new Date().getTime(),
      //     "event_type": uni.getStorageSync('event_type'),
      //     "purchase_amount": uni.getStorageSync('purchase_amount'),
      //   },
      //   success: function(res) {
      //     console.log('++++++++++ success   ++++++++++++++++')
      //     console.log(JSON.stringify(res.data))
      //     uni.removeStorageSync('cili')
      //     uni.removeStorageSync('event_type')
      //     uni.removeStorageSync('purchase_amount')
      //   },
      //   error: function(err) {
      //     console.log('++++++++++ error   ++++++++++++++++')
      //     console.log(JSON.stringify(err))
      //   },
      //   finally: function(res) {
      //     console.log('++++++++++ finally   ++++++++++++++++')
      //   }
      // })
    },
    sendtoTaqbxm:function () {
      uni.request({
        method:'GET',
        url: 'https://openlog.bianxianmao.com/inads/s.gif',
        header: {},
        data: {
          mt:8,
          bxmid:uni.getStorageSync('bxmid'),
          conversion_type:uni.getStorageSync('event_type'),
        },
        success: function(res) {
          console.log('++++++++++ success   ++++++++++++++++')
          console.log(JSON.stringify(res.data))
          uni.removeStorageSync('bxmid')
          uni.removeStorageSync('event_type')
        },
        error: function(err) {
          console.log('++++++++++ error   ++++++++++++++++')
          console.log(JSON.stringify(err))
        },
        finally: function(res) {
          console.log('++++++++++ finally   ++++++++++++++++')
        }
      })
    },
	}
};
</script>

<style>
.wanl-success .content {
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
}

.wanl-success .content .icon {
	font-size: 180rpx;
	color: #3aa112;
	margin-top: 150rpx;
}
.wanl-success .content .button {
	width: 100%;
}
</style>
